package org.jetnuke.modules.admin.download;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.DownloadsDownloads;
import org.jetnuke.util.JetUtil;

public class AddDownload implements IAction {
	String title, url, description, name, email, version, home;

	String submitter = "";

	int parent, filesize, hits;

	public void setDescription(String description) {
		this.description = description;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setFilesize(int filesize) {
		this.filesize = filesize;
	}

	public void setHits(int hits) {
		this.hits = hits;
	}

	public void setHome(String home) {
		this.home = home;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParent(int parent) {
		this.parent = parent;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.common.IAction#exec(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse,
	 *      org.apache.velocity.VelocityContext, org.jetnuke.common.IModuleInfo,
	 *      java.lang.String, org.jetnuke.common.IUserInfo,
	 *      org.jetnuke.common.IAdminInfo)
	 */
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {

		if (ai == null || (!ai.IsSuperUser() && !ai.isAdminDownload()))
			return null;//Error;
		DownloadsDownloads dd=new DownloadsDownloads();
		//downloads_downloads dd = new downloads_downloads();
		dd.setCID(parent);
		dd.setDESCRIPTION(description);
		dd.setEMAIL(email);
		dd.setFILESIZE(filesize);
		dd.setHITS(hits);
		dd.setHOMEPAGE(home);
		dd.setNAME(name);
		dd.setTITLE(title);
		dd.setURL(url);
		dd.setSUBMITTER(submitter);
		dd.setVERSION(version);
		DataAccessDriver.getInst().newDownloadDownloadDAO().addNew(dd);
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/admin/download");
		return null;
	}

}
